package com.woniuxy.thred.state;

/**
 * description: BlockedSleep01 <br>
 * date: 2022/2/5 5:32 下午 <br>
 * author: shesaifei <br>
 * version: 1.0 <br>
 */

/**
 * sleep模拟网络延时，放大发生问题的可能性
 */
public class BlockedSleep01 implements Runnable {
    //票数
    private int ticketNums = 99;

    @Override
    public void run() {
        while (true) {
            if (ticketNums < 0) {
                break;
            }
            //模拟延时
            try {
                Thread.sleep(200);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName() + "-->" + ticketNums--);
        }
    }

    public static void main(String[] args) {
        //一份资源
        BlockedSleep01 web = new BlockedSleep01();
        //多个代理
        System.out.println(Thread.currentThread().getName());
        new Thread(web, "zs").start();
        new Thread(web, "ls").start();
        new Thread(web, "ww").start();
    }
}
